package cn.smdq.ch.common.util;

import cn.smdq.ch.common.core.exception.BaseException;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;

/**
 * @author shuimodanqing
 * create at:  2019/1/29  5:18 PM
 * @description url工具类
 */
public class UrlUtil {

    public static String encode(String original, String charset) {
        try {
            return URLEncoder.encode(original, charset);
        } catch (UnsupportedEncodingException e) {
            throw new BaseException("url编码异常 : " + e.getMessage());
        }
    }

    public static String decode(String original, String charset) {
        try {
            return URLDecoder.decode(original, charset);
        } catch (UnsupportedEncodingException e) {
            throw new BaseException("url解码异常 : " + e.getMessage());
        }
    }
}
